package net.slidinglive.utilities.model;

import java.util.Calendar;
import java.util.Date;

import net.slidinglive.utilities.util.Constants;
import android.database.Cursor;

/**
 * @author Sebastian Hoffmann <bo.hoffi@gmail.com>
 */
public class Message {

    private int id;
    private int conversationId;
    /**
     * Telephone number
     */
    private String address;
    private int personId;
    private Date date;
    private int protocol;
    private boolean read;
    private int status;
    private int type;
    private String subject;
    private String body;

    public Message() {

    }

    public Message(final Cursor messageCursor) {

        this.setId(messageCursor.getInt(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_ID)));
        this.setConversationId(messageCursor.getInt(messageCursor
                .getColumnIndex(Constants.MESSAGE_COLUMN_CONVERSATION_ID)));
        this.setAddress(messageCursor.getString(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_ADDRESS)));
        this.setPersonId(messageCursor.getInt(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_PERSON)));
        this.setProtocol(messageCursor.getInt(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_PROTOCOL)));
        this.setRead(messageCursor.getInt(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_READ)));
        this.setStatus(messageCursor.getInt(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_STATUS)));
        this.setType(messageCursor.getInt(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_TYPE)));
        this.setSubject(messageCursor.getString(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_SUBJECT)));
        this.setBody(messageCursor.getString(messageCursor.getColumnIndex(Constants.MESSAGE_COLUMN_BODY)));
    }

    public String toDebugString() {

        final StringBuilder output = new StringBuilder();
        output.append(Constants.MESSAGE_COLUMN_ID).append(": ").append(this.getId());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_CONVERSATION_ID).append(": ").append(this.getConversationId());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_ADDRESS).append(": ").append(this.getAddress());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_PERSON).append(": ").append(this.getPersonId());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_DATE).append(": ").append(this.getDate());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_PROTOCOL).append(": ").append(this.getProtocol());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_READ).append(": ").append(this.getRead());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_STATUS).append(": ").append(this.getStatus());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_TYPE).append(": ").append(this.getType());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_SUBJECT).append(": ").append(this.getSubject());
        output.append("\n");
        output.append(Constants.MESSAGE_COLUMN_BODY).append(": ").append(this.getBody());

        return output.toString();
    }

    /**
     * @return the id
     */
    public int getId() {

        return this.id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(int id) {

        this.id = id;
    }

    /**
     * @return the conversationId
     */
    public int getConversationId() {

        return this.conversationId;
    }

    /**
     * @param conversationId
     *            the conversationId to set
     */
    public void setConversationId(int conversationId) {

        this.conversationId = conversationId;
    }

    /**
     * @return the address
     */
    public String getAddress() {

        return this.address;
    }

    /**
     * @param address
     *            the address to set
     */
    public void setAddress(String address) {

        this.address = address;
    }

    /**
     * @return the person
     */
    public int getPersonId() {

        return this.personId;
    }

    /**
     * @param person
     *            the person to set
     */
    public void setPersonId(int person) {

        this.personId = person;
    }

    /**
     * @return the date
     */
    public Date getDate() {

        return this.date;
    }

    /**
     * @param date
     *            the date to set
     */
    public void setDate(Date date) {

        this.date = date;
    }

    public void setDate(long timestamp) {

        final Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(timestamp);

        this.date = cal.getTime();
    }

    /**
     * @return the protocol
     */
    public int getProtocol() {

        return this.protocol;
    }

    /**
     * @param protocol
     *            the protocol to set
     */
    public void setProtocol(int protocol) {

        this.protocol = protocol;
    }

    /**
     * @return the read
     */
    public boolean getRead() {

        return this.read;
    }

    /**
     * @param read
     *            the read to set
     */
    public void setRead(boolean read) {

        this.read = read;
    }

    /**
     * @param read
     *            the read to set
     */
    public void setRead(int read) {

        this.read = (read == 1) ? true : false;
    }

    /**
     * @return the status
     */
    public int getStatus() {

        return this.status;
    }

    /**
     * @param status
     *            the status to set
     */
    public void setStatus(int status) {

        this.status = status;
    }

    /**
     * @return the type
     */
    public int getType() {

        return this.type;
    }

    /**
     * @param type
     *            the type to set
     */
    public void setType(int type) {

        this.type = type;
    }

    /**
     * @return the subject
     */
    public String getSubject() {

        return this.subject;
    }

    /**
     * @param subject
     *            the subject to set
     */
    public void setSubject(String subject) {

        this.subject = subject;
    }

    /**
     * @return the body
     */
    public String getBody() {

        return this.body;
    }

    /**
     * @param body
     *            the body to set
     */
    public void setBody(String body) {

        this.body = body;
    }
}